package com.smmisia.auth.controller;


import com.smmisia.common.request.auth.RoleRequest;
import com.smmisia.auth.service.SysRoleService;
import com.smmisia.common.Result.Result;
import com.smmisia.common.entity.auth.SysRole;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: smmisia
 * @date: 2023-09-08
 * @description: 权限管理
 */
@RestController
@RequestMapping("/role")
@Slf4j
@Tag(name = "角色管理")
public class RoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 添加角色
     *
     * @param roleRequest
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "添加角色", description = "添加角色")
    public Result<String> addRole(@Valid @RequestBody RoleRequest roleRequest) {
        return sysRoleService.addRole(roleRequest);
    }

    /**
     * 删除角色
     *
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result<String> deleteRole(@RequestParam(name = "id") @NotNull(message = "id不能为空") Integer id) {
        return sysRoleService.deleteRole(id);
    }

    /**
     * 修改角色
     *
     * @param roleRequest
     * @return
     */
    @PostMapping("/update")
    public Result<String> updateRole(@Valid @RequestBody RoleRequest roleRequest) {
        return sysRoleService.updateRole(roleRequest);
    }

    /**
     * 获取角色列表
     *
     * @return
     */
    @GetMapping("/list")
    public Result<List<SysRole>> getRole(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return sysRoleService.getRole(pageNum, pageSize);
    }

    /**
     * 获取角色信息
     *
     * @return
     */
    @GetMapping("/info")
    public Result<SysRole> getRoleInfo(@RequestParam(name = "id") @NotNull(message = "id不能为空") Integer id) {
        return sysRoleService.getRoleInfo(id);
    }
}